/*******************************************************************************
 * Copyright (c) 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.core.internal.api;

import java.util.ArrayList;
import java.util.Map;

import net.sourceforge.perforce.core.PerforceCorePlugin;
import net.sourceforge.perforce.core.api.IPerforceServer;
import net.sourceforge.perforce.core.internal.model.P4Label;

import org.eclipse.core.runtime.MultiStatus;

/** ClientUser object for the 'p4 labels' command.
  * 
  * @version $Revision: 216 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class Labels extends AbstractPerforceCommand
{	
	// --------------------------------------------------------------------------- Private Variables

	/** Stores the results of the operation. */
	private ArrayList resultList = new ArrayList();
	/** Stores the Perforce Server. */
	private IPerforceServer server;
	
	// ------------------------------------------------------------------------- Public Constructors
	
	/** Constructor for Labels. 
	  * 
	  * @param theServer the perforce server that executes the command.
	  */
	public Labels(IPerforceServer theServer)
	{
		super(
			new MultiStatus(
				PerforceCorePlugin.ID, 0, "Error during 'p4 labels'.", null));         //$NON-NLS-1$
				
		server = theServer;
	}
	
	// ------------------------------------------------------------------------------ Public Methods
	
	/** @see AbstractPerforceCommand#outputStat(Map) */
	public void outputStat(Map strDict)
	{
		P4Label label = new P4Label(server, Helper.safeGetString(strDict, "label"));       //$NON-NLS-1$
		label.setLastUpdate(Helper.safeGetDate(strDict, "Update"));                    //$NON-NLS-1$
		label.setLastAccess(Helper.safeGetDate(strDict, "Access"));                    //$NON-NLS-1$
		label.setOwner(Helper.safeGetString(strDict, "Owner"));                        //$NON-NLS-1$
		label.setDescription(Helper.safeGetString(strDict, "Description"));            //$NON-NLS-1$
		
		boolean locked = "locked".equals(Helper.safeGetString(strDict, "Options"));    //$NON-NLS-1$
		label.setLocked(locked);
		
		resultList.add(label);
	}
	
	/** Called to retrieve the result of the operation. 
	  *
	  * @return array of labels. 
	  */
	public P4Label[] getResult()
	{
		return (P4Label[]) resultList.toArray(new P4Label[resultList.size()]);
	}
	
	/** @see IPerforceCommand#getCommand() */
	public String getCommand()
	{
		return "labels";                                                               //$NON-NLS-1$
	}
}
